package com.sofwin.controller;

import com.sofwin.Constants;
import com.sofwin.common.ResponseData;
import com.sofwin.pojo.SysUser;
import com.sofwin.pojo.vo.NavMenu;
import com.sofwin.system.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @packageName: com.sofwin.controller
 * @user: andyliu
 * @date: 2021/9/17 16:41
 * @email 115176513@qq.com
 * @description: TODO
 */
@RestController
public class LoginController {

    @Reference
    private UserService userService;

    @PostMapping("/login")
    public ResponseData login(SysUser user, HttpSession session,String code){
        String mcode = session.getAttribute(Constants.KAPTCHA_KEY).toString();
        if(!code.equals(mcode)){
            return new ResponseData(602,"验证码错误");
        }
        ResponseData data  = userService.checkLogin(user);
        if(data.getCode()==200) {
            user = userService.queryUserByUserName(user.getLoginName());
            session.setAttribute(Constants.CURR_USER, user);
        }
        return data;
    }
}
